import express, {Request, Response} from 'express';
import path from 'path';
import cors from 'cors';

const app = express();
const PORT = 8080;

// 中间件
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(cors());

// 静态文件服务
app.use(express.static(path.join(__dirname, '../../client')));

// 登录验证接口
app.post('/api/login', (req: Request, res: Response) => {
    const {username, password} = req.body;

    // 假的校验逻辑
    if (username === 'root' && password === '123456') {
        res.status(200).json({
            success: true,
            message: '验证通过'
        });
    } else {
        res.status(401).json({
            success: false,
            message: '对不起，用户或者密码不正确'
        });
    }
});

// 启动服务器
app.listen(PORT, () => {
    console.log(`服务器运行在 http://localhost:${PORT}`);
});
